package com.fujimana.rockincat.restree.phase;

import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;


public class PrepareRequestPhase implements Phase {

	@Override
	public void execute(Map<String, Object> context) {
		
		HttpServletRequest request = (HttpServletRequest) context.get(HttpServletRequest.class.getName());

		String contentType = request.getContentType();
		Locale locale = request.getLocale();
		String charset = request.getCharacterEncoding();
		
		if(contentType == null || contentType.trim().equals("")) {
			contentType = "text/plain";
		}
		
		if(locale == null) {
			locale = Locale.getDefault();
		}
		
		if(charset == null || charset.trim().equals("")) {
			charset = System.getProperty("file.encoding");
		}

		context.put("contentType", contentType);
		context.put("locale", locale);
		context.put("charset", charset);
	}

	@Override
	public String getId() {
		return PrepareRequestPhase.class.getSimpleName();
	}

	@Override
	public boolean isChain() {
		return true;
	}

}
